<?php

include_once './libs/config.php';
/*
 * 1.login and out   (finished)
 * 2.get exceptional date array;(finished)
 * 3 similary to part2, and get duty array.(finished)
 * 4.update person detial
 * 
 */

/**
 * Description of stuff
 *
 * @author markxi
 */
class staff {

    //step 1 part1
    protected $id;
    protected $email; //name refactor to email
    protected $givenName;
    protected $pw;
    protected $logState = false;
    protected $DBconfig;
    protected $dbName;
    protected $initial;
    //end of step 1 part1
    //step 2 part1
    protected $willingArray = array();
    protected $unableDateArray = array();
    //end of step 2 part1
    //step3 part1
    protected $dutyDateArray; //variable to contain the final duty in format like {date,active}

    //end of step 3 part1
    //session


    //step1 part2
    
    public function initial($Name, $PW){
        $this->givenName = $Name;
        $this->pw = $PW;
    }

   
    public function __construct($Email, $PW) {
        $this->DBconfig = new DBconfig();
        $this->checkPW($Email, $PW);
    }
    
    public function setIntial($Initial){
        $this->initial = $Initial;
    }
    public function getInitial(){
        return $this->initial;
    }
    public function showInitial(){
        echo $this->initial;
    }
    public function setName($Name){
        $this->givenName = $Name;
    }
    
    public function getDbconfig(){
        return $this->DBconfig;
    }

    public function getName() {
        return $this->givenName;
    }
    
    public function showName(){
        echo $this->givenName;
    }
    public function setDBName($dbName){
        $this->dbName = $dbName;
    }
    public function getDBName(){
        return $this->dbName;
    }
    public function showDBName(){
        echo $this->dbName;
    }

    public function setPW($tempPW) {
        $this->pw = $tempPW;
    }

    public function getLoginState() {
        return $this->logState;
    }

    public function login() {
        $this->logState = true;
    }

    public function logout() {
        $this->logState = false;
    }
    
    public function setId($ID){
        $this->id = $ID;
    }
    public function showID(){
        echo $this->id;
    }
    
    public function getID(){
        return $this->id;
    }

    public function checkPW($email, $pw) {

        $sql = "SELECT user_id,gName,pw,email,rosterDBName,initial FROM `roster_users`.`users` WHERE email = '$email'";

        $this->DBconfig->DB->query($sql);
        echo '<pre>';
        $result = $this->DBconfig->DB->get();
        if (count($result) > 0) {
            //print_r($result);
            //print_r($result[0]['pw']);
            if ($result[0]['pw'] == $pw) {
                $this->login();
                $this->setId($result[0]['user_id']);
                $this->setDBName($result[0]['rosterDBName']);
                $this->setName($result[0]['gName']);
                $this->setIntial($result[0]['initial']);
                echo "login in<br>";
            } else {
                echo("pw is incorrect<br>");
            }
        } else {
            echo('no such user<br>');
        }
    }

    //end of step1 part2
    //stpe 2 part2
    public function setWillingArray($WillingArray) {
        $this->willingArray = $WillingArray;
    }

    public function getWillingArray() {
        return $this->willingArray;
    }
    public function showWillingArray(){
        echo '<pre>';
        print_r($this->willingArray);
    }

    public function setUnableArray($UnableArray) {
        $this->unableDateArray = $UnableArray;
    }

    public function getUnableArray() {
        return $this->unableDateArray;
    }
    
    public function showUnableArray(){
        echo '<pre>';
        print_r($this->unableDateArray);//need to arsort the array in time order
    }

    //end of step2 part2
    //step 3 part2
    public function getDutyDateArray() {
        return $this->dutyDateArray;
        //conenction to DB and get the final data.
    }
    

}

?>
